﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Member_Master.Master" AutoEventWireup="true" CodeBehind="M_ProductCategory.aspx.cs" Inherits="WebApplication.M_ProductCategory" %>
<%@ Register TagPrefix="uc1" TagName="usermeg" Src="~/UserControl/M_UserMessageControl.ascx" %>
<%@ Register TagPrefix="uc1" TagName="maintab" Src="~/UserControl/M_MainTabControl.ascx" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajax" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
<link href="Media/Css/master2.css" rel="stylesheet" media="all"/>
<link href="Media/Css/PeterCss.css" rel="Stylesheet" media="all" />
<script type="text/javascript">
    $(document).ready(function () {
        $("#menu1_ul1").find("li").each(function (i) {
            $(this).click(function () { $(this).children("span").toggleClass("span" + (i + 1)); });
        });

        $("#menu1_ul1").find(".li1").children("span").addClass("span1");
        $("#div_A").css("display", "block");

        //产品大分类 菜单
        $("#menu1_ul1").find("li").each(function (i) {
            $(this).click(function () {
                $("#menu1_ul1").find("li").children("span").removeAttr("class");
                $(this).children("span").addClass("span" + (i + 1));
                display_productcategory($(this).children("span").attr("title"));
            });
        });


        $.each(['A', 'B', 'C', 'D', 'E'], function (k, v) {
            //各category全选All 事件
            $("#ContentPlaceHolder2_rp_Cate_All_cb_all_" + k).click(function () {
                if ($(this).attr("checked") == true) {
                    $("#div_" + v).find("input").not($(this)).attr("checked", 'true');
                    //$("#menu1_ul1 .li" + (k + 1) + " .selected").html("√");
                }
                else {
                    $("#div_" + v).find("input").not($(this)).attr("checked", '');
                    // $("#menu1_ul1 .li" + (k + 1) + " .selected").html("");
                }
            });


            /////category 事件
            $("#ContentPlaceHolder2_rp_Cate_All_cbl_cate_" + k + " td input").click(function () {
                var source = $(this).attr("id").toString();
                var p = source[41];
                var c = source[43];

                if ($(this).attr("checked") == true) {
                    $("#ContentPlaceHolder2_rp_Cate_All_rp_cate_" + p + "_cbl_subcate_" + c + " input").attr("checked", 'true');
                }
                else {
                    $("#ContentPlaceHolder2_rp_Cate_All_rp_cate_" + p + "_cbl_subcate_" + c + " input").attr("checked", '');
                }
                SubItemCheck(k);
            });



            ///subcategory 事件
            $("#div_" + v).find("input").not("#ContentPlaceHolder2_rp_Cate_All_cb_all_" + k).not("#ContentPlaceHolder2_rp_Cate_All_cbl_cate_" + k + " input").click(function () {
                SubItemCheck(k);
                // hasChSelect();
            });

            $(".cate_and_sub").find("input[type='checkbox']").click(function () {
                hasChSelect();
            })


            SubItemCheck(k);

        });

        hasChSelect();
    });


    //根据子项选中情况 绑定父项（所以的子项全选的时候 父项选中，子项任何一个未选父项设为未选）！
    function SubItemCheck(mainItemIndex) {
        var catagoryIndex = $("#ContentPlaceHolder2_rp_Cate_All_cbl_cate_" + mainItemIndex + " td").find("input").length;
        for (i = 0; i < catagoryIndex; i++) {
            var subcategory = $("#ContentPlaceHolder2_rp_Cate_All_rp_cate_" + mainItemIndex + "_cbl_subcate_" + i + " td").find("input"); //ContentPlaceHolder2_rp_Cate_All_rp_cate_0_cbl_subcate_1
            var allChildChecked = true;

            $.each(subcategory, function (j) {
                if (subcategory.eq(j).attr("checked") != true) {
                    allChildChecked = false;
                    return false;
                }
                else {
                    return true;
                }
            });


            if (allChildChecked == true) {
                $("#ContentPlaceHolder2_rp_Cate_All_cbl_cate_" + mainItemIndex + "_" + i + "_" + mainItemIndex).attr("checked", 'true');  //ContentPlaceHolder2_rp_Cate_All_cbl_cate_0_1_0
            }
            else {
                $("#ContentPlaceHolder2_rp_Cate_All_cbl_cate_" + mainItemIndex + "_" + i + "_" + mainItemIndex).attr("checked", '');
            }
        }


        var allParentChecked = true;
        var tmp_category_item = $("#ContentPlaceHolder2_rp_Cate_All_cbl_cate_" + mainItemIndex + " td").find("input");
        $.each(tmp_category_item, function (i) {
            if (tmp_category_item.eq(i).attr("checked") != true) {
                allParentChecked = false;
                return false;
            }
            else {
                return true;
            }
        });
        if (allParentChecked == true) {
            $("#ContentPlaceHolder2_rp_Cate_All_cb_all_" + mainItemIndex).attr("checked", 'true');
            // $("#menu1_ul1 .li" + (mainItemIndex+1) + " .selected").html("√");
        }
        else {
            $("#ContentPlaceHolder2_rp_Cate_All_cb_all_" + mainItemIndex).attr("checked", '');
            //  $("#menu1_ul1 .li" + (mainItemIndex+1) + " .selected").html("");
        }

    }


    //隐藏所有 显示特定的
    function display_productcategory(i) {
        $("#id_check_container").find(".cate_and_sub").css("display", "none");
        $("#div_" + i).css("display", "block");
    }

    function hasChSelect() {
        $("#id_check_container").find(".cate_and_sub").each(function (i) {

            var has = false;
            $(this).find("input[type='checkbox']").each(function () {
                if ($(this).attr('checked')) {
                    has = true;
                    return false;
                }
            })


            if (has) {

                $("#menu1_ul1").find(".li" + (i + 1)).find(".selected").html("√")

            }
            else
                $("#menu1_ul1").find(".li" + (i + 1)).find(".selected").html(" ");

        })

    }
    function GetInfo() {
        GetChangeVal();
        if ($("#ContentPlaceHolder2_lkBtnSave").hasClass("aspNetDisabled").toString() != "true") {
            $("#ContentPlaceHolder2_lblMeg").html("Data being processed, please wait...");
        } else {
            $("#ContentPlaceHolder2_lblMeg").html("You currently do not have permission to operate...");
        }
        //var t = setTimeout(timeOut, 10000);
    }

    function timeOut() {
        $("#ContentPlaceHolder2_lblMeg").html("");
    }

    function Quit() {
        $("#ContentPlaceHolder2_lblMeg").html("Cancel your operation...");
    }

    function GetChangeVal() {
        var addVal = "";
        var proVal = "";
        var delVal = "";
        var hiddenStr = $("#ContentPlaceHolder2_HiddenField_val").val();
        var hiddenVal = hiddenStr.substring(0, hiddenStr.length - 1).split(",");

        $("div").find(".Pro_Cat").find("input:checked").each(function (m, n) {
            var has = true;
            for (j = 0; j < hiddenVal.length; j++) {
                if (n.value == hiddenVal[j]) {
                    has = false;
                    break;
                }
            }
            if (has) {
                addVal += n.value + ",";
            }
            else {
                proVal += n.value + ",";
            }
        });
        
        proVal = proVal.substring(0, proVal.length - 1).split(",");

        for (i = 0; i < hiddenVal.length; i++) {
            var has = true;
            for (j = 0; j < proVal.length; j++) {
                if (hiddenVal[i] == proVal[j]) {
                    has = false;
                    break;
                }
            }
            if (has) {
                delVal += hiddenVal[i] + ",";
            }
        }

        $("#ContentPlaceHolder2_HiddenFiled_add").attr("value", addVal);
        $("#ContentPlaceHolder2_HiddenFiled_del").attr("value", delVal);
    }
</script>

</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<div class="content-title">
        <h1>
            Membership Info</h1>
    </div>
    <input type="hidden" value="t6" id="pageName" />
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="ContentPlaceHolder2" runat="server">
<asp:ScriptManager ID="manager1" runat="server" EnablePartialRendering="true"></asp:ScriptManager>
<uc1:usermeg ID="usermeg" runat="server" ></uc1:usermeg>

    <div class="partWrap">
	<uc1:maintab ID="maintab"  runat="server"/>	
    <div class="clear20"></div>
    <div class="productWrap">
	<div class="productTitle"></div>

  <div id="id_check_container" class="CheckWrap">
                <ul class="menu1_ul menu1" id="menu1_ul1">

                    <li class="li1">
                        <div class="selected">
                            √</div>
                        <span title="A">Textile & Garment</span></li>
                    <li class="li2">
                        <div class="selected" style="color: #ffffff;">
                            √</div>

                        <span title="B">Electronics, AV & IT</span></li>
                    <li class="li3">
                        <div class="selected" style="color: #ffffff;">
                            √</div>
                        <span title="C">Houseware</span></li>
                    <li class="li4">
                        <div class="selected">

                            √</div>
                        <span title="D">Gifts & Premium</span></li>
                    <li class="li5">
                        <div class="selected">
                            √</div>
                        <span title="E">Others</span></li>

                </ul>
  
                             <h4 class="title20">
                    Main Category</h4>
                    <asp:Repeater ID="rp_Cate_All" runat="server" OnItemDataBound="rp_Cate_All_ItemDataBound">
                    <ItemTemplate>
                        <div id="<%# "div_"+Container.DataItem %>" style="display: none;" class="cate_and_sub">
                            <p>
                                <asp:CheckBox ID="cb_all" runat="server" Text="<strong>All</strong>" /><br />
                            </p>
                            <asp:CheckBoxList ID="cbl_cate" runat="server" RepeatColumns="3" RepeatDirection="Horizontal"
                                Width="100%" CellPadding="0" CellSpacing="0" CssClass="labelTb">
                            </asp:CheckBoxList>
                            <br />
                            <br />
                            <asp:Repeater ID="rp_cate" runat="server" OnItemDataBound="rp_cate_ItemDataBound">
                                <ItemTemplate>
                                    <p>
                                        <b>
                                            <%#Eval("ProductCat_Eng") + " " + Eval("ProductCat_Chi")%></b><asp:HiddenField ID="hdProductCatUID"
                                                runat="server" Value='<% # Eval("ProductCatUID")%>' />
                                    </p>
                                    <asp:CheckBoxList ID="cbl_subcate" runat="server" RepeatColumns="3" RepeatDirection="Horizontal"
                                        Width="100%" CellPadding="0" CellSpacing="0" CssClass="labelTb Pro_Cat">
                                    </asp:CheckBoxList>
                                    <br />
                                </ItemTemplate>
                            </asp:Repeater>
                        </div>
                    </ItemTemplate>
                </asp:Repeater>
                <asp:HiddenField runat="server" ID="HiddenField_val" />
                <asp:HiddenField runat="server" ID="HiddenFiled_add" />
                <asp:HiddenField runat="server" ID="HiddenFiled_del" />
		<div class="clear20"></div>
		
</div><!-- CheckWrap end-->
    </div><!-- productWrap end-->
    <div class="clear20"></div>
    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <ContentTemplate>
	        <table width="200" border="0" cellspacing="0" cellpadding="0">
	          <tr>
	            <td width="80">
	            <ul class="uibtn">
    	            <li onClick="javascript:ToggleDocument('wrapToggle')">
                    <span>
                    <asp:LinkButton ID="LbtnSave" runat="server" OnClick="LbtnSave_Click" OnClientClick="return GetInfo()">Save</asp:LinkButton>
                    </span>
                    </li>
	            </ul>
	        </td>
	        <td>
	        <ul class="uibtn">
    	        <li  onClick="javascript:ToggleDocument('wrapToggle')"><span><asp:LinkButton ID="LbtnQuit" runat="server" OnClick="LbtnQuit_Click" OnClientClick="return Quit()">Quit</asp:LinkButton></span></li>
	        </ul>
		        </td>				
		        </tr>
	        </table>
            <asp:Label ID="lblMeg" runat="server" CssClass="clsWarningMeg"></asp:Label>
        </ContentTemplate>
    </asp:UpdatePanel>	
</div><!-- partWrap end-->
</asp:Content>
